package com.holyn.guofang.presenter.distinguish;

import com.holyn.guofang.model.webhttp.RetrofitManager;
import com.holyn.guofang.model.webhttp.observable.DataDictionaryObservable;
import com.holyn.guofang.model.webhttp.wo.ImageBasicWo;
import com.holyn.guofang.presenter.AbstractBasePresenterImp;
import com.holyn.guofang.presenter.BaseView;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;

/**
 * Created by Holyn on 2017/7/23.
 */

public class ImageElementPresenter extends ImageElementContract.Presenter{
    private DataDictionaryObservable dataDictionaryObservable;
    private ImageElementContract.View responseView;

    public ImageElementPresenter(BaseView baseView) {
        super(baseView);
        dataDictionaryObservable = RetrofitManager.getCommonObservable(DataDictionaryObservable.class);
    }

    @Override
    public void addView(ImageElementContract.View responseView) {
        this.responseView = responseView;
    }

    @Override
    public void postImageBasicList(final int requestAction, String parentCode, Integer pageSize, Integer page) {
        getCommonObservable(requestAction, dataDictionaryObservable.imageBasicList(parentCode, pageSize, page))
                .subscribe(new Consumer<ImageBasicWo>() {
                    @Override
                    public void accept(@NonNull ImageBasicWo imageBasicWo) throws Exception {
                        responseView.responseSuccess(requestAction, imageBasicWo);
                    }
                });
    }
}
